package akka.streams

import akka.NotUsed
import akka.stream.scaladsl.{Flow, Sink, Source}

/**
  * Created by shichen on 2017/7/6.
  * http://doc.akka.io/docs/akka/2.5.3/scala/stream/stream-composition.html
  */
object OfficialDocs {
  val nestedSource = Source.single(0) //an atomic source
    .map(_ + 1) //an atomic processing stage
    .named("nestedsource") // wrap up the current and gives it a name

  val nestedFlow = Flow[Int].filter(_ != 0)
    .map(_ - 2)
    .named("nestedFlow")
  val nestedSink = nestedFlow.to(Sink.fold(0)(_ + _))
    .named("nestedSink")

  val runnableGraph = nestedSource.to(nestedSink)

}
